import request from '@/utils/request'

export interface ItemDTO {
  id?: number
  name: string
  price: number
  stock: number
  image: string
  category: string
  brand: string
  spec: string
  sold: number
  commentCount: number
  isAD: boolean
  status: number
  createTime?: string
  updateTime?: string
  creater?: number
  updater?: number
}

export interface ItemPageQuery {
  pageNo: number
  pageSize: number
  key?: string
  brand?: string
  category?: string
  minPrice?: number
  maxPrice?: number
}

export interface ApiResponse<T = any> {
  code: number
  msg: string
  data: T
}

export interface PageDTO<T> {
  list: T[]
  total: number
}

// 获取商品列表（分页查询）
export const getItemList = (params: ItemPageQuery) => {
  return request({
    url: '/items/page',
    method: 'get',
    params
  })
}

// 根据分类分页查询商品
export const getItemsByCategory = (category: string, params: Omit<ItemPageQuery, 'category'>) => {
  return request({
    url: `/items/category/${category}/page`,
    method: 'get',
    params
  })
}

// 获取所有商品分类
export const getAllCategories = () => {
  return request({
    url: '/items/categories',
    method: 'get'
  })
}

// 根据id查询商品
export const getItemById = (id: number) => {
  return request({
    url: `/items/${id}`,
    method: 'get'
  })
}

// 根据id批量查询商品
export const getItemsByIds = (ids: number[]) => {
  return request({
    url: '/items',
    method: 'get',
    params: { ids }
  })
}

// 搜索商品
export const searchItems = (params: ItemPageQuery) => {
  return request({
    url: '/search/list',
    method: 'get',
    params
  })
} 